class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int num1 = 0, num2 = 0;
        for (auto& x : nums) num1 += x;
        for (int i = 0; i < nums.size(); i++)
        {
            num1 -= nums[i];
            if (num2 == num1) return i;
            num2 += nums[i];
        }
        return -1;
    }
};